﻿using System;
using System.Diagnostics.Contracts;
using NLog;

namespace YasharEl.Infrastructure.Diagnostics.Logging.NLog
{
    public class NLogLogger<T> : BaseLogger<T>
    {
        #region Fields

        private readonly Logger nLogLogger;

        #endregion

        #region Constructors

        public NLogLogger(Logger nLogLogger)
        {
            Contract.Requires<ArgumentNullException>(nLogLogger != null, "NLogLogger could not be null.");
            this.nLogLogger = nLogLogger;
        }

        #endregion

        #region BaseLogger<T> Implementations

        public override bool IsDebugEnabled
        {
            get { return nLogLogger.IsDebugEnabled; }
        }

        public override bool IsErrorEnabled
        {
            get { return nLogLogger.IsErrorEnabled; }
        }

        public override bool IsFatalEnabled
        {
            get { return nLogLogger.IsFatalEnabled; }
        }

        public override bool IsInfoEnabled
        {
            get { return nLogLogger.IsInfoEnabled; }
        }

        public override bool IsWarnEnabled
        {
            get { return nLogLogger.IsWarnEnabled; }
        }

        public override void Debug(string format, params object[] args)
        {
            nLogLogger.Debug(string.Format(format, args));
        }

        public override void Debug(Exception exception, string format, params object[] args)
        {
            nLogLogger.Debug(string.Format(format, args), exception);
        }

        public override void Error(string format, params object[] args)
        {
            nLogLogger.Error(string.Format(format, args));
        }

        public override void Error(Exception exception, string format, params object[] args)
        {
            nLogLogger.Error(string.Format(format, args), exception);
        }

        public override void Fatal(string format, params object[] args)
        {
            nLogLogger.Fatal(string.Format(format, args));
        }

        public override void Fatal(Exception exception, string format, params object[] args)
        {
            nLogLogger.Fatal(string.Format(format, args), exception);
        }

        public override void Info(string format, params object[] args)
        {
            nLogLogger.Info(string.Format(format, args));
        }

        public override void Info(Exception exception, string format, params object[] args)
        {
            nLogLogger.Info(string.Format(format, args), exception);
        }

        public override void Warn(string format, params object[] args)
        {
            nLogLogger.Warn(string.Format(format, args));
        }

        public override void Warn(Exception exception, string format, params object[] args)
        {
            nLogLogger.Warn(string.Format(format, args), exception);
        }

        #endregion
    }

    public class NLogLogger : ILogger
    {
        #region Fields

        private readonly Logger nLogLogger;

        #endregion

        #region Constructors

        public NLogLogger(Logger nLogLogger)
        {
            Contract.Requires<ArgumentNullException>(nLogLogger != null, "nLogLogger could not be null.");
            this.nLogLogger = nLogLogger;
        }

        #endregion

        #region ILogger Implementations

        public bool IsDebugEnabled
        {
            get { return nLogLogger.IsDebugEnabled; }
        }

        public bool IsErrorEnabled
        {
            get { return nLogLogger.IsErrorEnabled; }
        }

        public bool IsFatalEnabled
        {
            get { return nLogLogger.IsFatalEnabled; }
        }

        public bool IsInfoEnabled
        {
            get { return nLogLogger.IsInfoEnabled; }
        }

        public bool IsWarnEnabled
        {
            get { return nLogLogger.IsWarnEnabled; }
        }

        public void Debug(string format, params object[] args)
        {
            nLogLogger.Debug(string.Format(format, args));
        }

        public void Debug(Exception exception, string format, params object[] args)
        {
            nLogLogger.Debug(string.Format(format, args), exception);
        }

        public void Error(string format, params object[] args)
        {
            nLogLogger.Error(string.Format(format, args));
        }

        public void Error(Exception exception, string format, params object[] args)
        {
            nLogLogger.Error(string.Format(format, args), exception);
        }

        public void Fatal(string format, params object[] args)
        {
            nLogLogger.Fatal(string.Format(format, args));
        }

        public void Fatal(Exception exception, string format, params object[] args)
        {
            nLogLogger.Fatal(string.Format(format, args), exception);
        }

        public void Info(string format, params object[] args)
        {
            nLogLogger.Info(string.Format(format, args));
        }

        public void Info(Exception exception, string format, params object[] args)
        {
            nLogLogger.Info(string.Format(format, args), exception);
        }

        public void Warn(string format, params object[] args)
        {
            nLogLogger.Warn(string.Format(format, args));
        }

        public void Warn(Exception exception, string format, params object[] args)
        {
            nLogLogger.Warn(string.Format(format, args), exception);
        }

        #endregion
    }
}
